import { defineStore } from 'pinia';

export const useGlobalStore = defineStore('global', {
    state: () => {
        let list = localStorage.getItem('cacheList');
        return {
            cacheList: list ? JSON.parse(list) : [],
        };
    },
    getters: {},
    actions: {
        handleCacheList(item) {
            this.cacheList = [...this.cacheList, item];
            localStorage.setItem('cacheList', JSON.stringify(this.cacheList));
        },
        delCacheItem(item) {
            this.cacheList = this.cacheList.filter(v => v !== item);
            localStorage.setItem('cacheList', JSON.stringify(this.cacheList));
        },
        handleReset() {
            this.cacheList = [];
        }
    }
});
